package com.yanqu.road.dao.impl.activity.fivehero;

import com.yanqu.road.dao.db.DbNameStrategy;
import com.yanqu.road.dao.impl.TempDao;
import com.yanqu.road.entity.activity.fivehero.config.*;

import java.sql.CallableStatement;
import java.sql.ResultSet;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class FiveHeroConfigDaoImpl extends TempDao {

    public static String get1Sql = "select * from t_s_activity_five_hero_type where activityId= ?";
    public Map<Integer, FiveHeroTypeConfig> getTypeConfigMap(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, FiveHeroTypeConfig> result = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(get1Sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FiveHeroTypeConfig data = new FiveHeroTypeConfig();
                data.setActivityId(rs.getInt("activityId"));
                data.setType(rs.getInt("type"));
                data.setName(rs.getString("name"));
                data.setCampPoint(rs.getInt("campPoint"));
                data.setCampScore(rs.getInt("campScore"));
                data.setTeamNum(rs.getInt("teamNum"));
                data.setPvpTeamDrawWeights(rs.getString("pvpTeamDrawWeights"));
                data.setPveTeamDrawWeights(rs.getString("pveTeamDrawWeights"));
                data.setAddition(rs.getInt("addition"));
                data.setEnergyCost(rs.getInt("energyCost"));
                data.setEventList(rs.getString("eventList"));
                data.setDiffPoolFightOrder(rs.getString("diffPoolFightOrder"));
                data.setBlood(rs.getString("blood"));
                result.put(data.getType(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
            //throw e;
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }

    public static String get2Sql = "select * from t_s_activity_five_hero_city where activityId= ?";
    public Map<Integer, FiveHeroCityConfig> getCityConfigMap(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, FiveHeroCityConfig> result = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(get2Sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FiveHeroCityConfig data = new FiveHeroCityConfig();
                data.setActivityId(rs.getInt("activityId"));
                data.setId(rs.getInt("id"));
                data.setName(rs.getString("name"));
                data.setType(rs.getInt("type"));
                data.setInitialCamp(rs.getInt("initialCamp"));
                data.setShowType(rs.getInt("showType"));
                data.setJobBuffEffect(rs.getString("jobBuffEffect"));
                result.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
            //throw e;
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }

    public static String get3Sql = "select * from t_s_activity_five_hero_buff where activityId= ?";
    public Map<Integer, FiveHeroBuffConfig> getBuffConfigMap(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, FiveHeroBuffConfig> result = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(get3Sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FiveHeroBuffConfig data = new FiveHeroBuffConfig();
                data.setActivityId(rs.getInt("activityId"));
                data.setId(rs.getInt("id"));
                data.setType(rs.getInt("type"));
                data.setIcon(rs.getInt("icon"));
                data.setName(rs.getString("name"));
                data.setDesc(rs.getString("desc"));
                data.setBuffEffect(rs.getString("buffEffect"));
                data.setContinueTime(rs.getInt("continueTime"));

                result.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
            //throw e;
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }

    public static String get4Sql = "select * from t_s_activity_five_hero_event where activityId= ?";
    public Map<Integer, FiveHeroEventConfig> getEventConfigMap(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, FiveHeroEventConfig> result = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(get4Sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FiveHeroEventConfig data = new FiveHeroEventConfig();
                data.setActivityId(rs.getInt("activityId"));
                data.setId(rs.getInt("id"));
                data.setType(rs.getInt("type"));
                data.setIcon(rs.getInt("icon"));
                data.setParameter(rs.getString("parameter"));
                data.setWeight(rs.getInt("weight"));
                data.setRewards(rs.getString("rewards"));
                data.setDesc(rs.getString("desc"));
                data.setKillRewards(rs.getString("killRewards"));
                data.setWinRewards(rs.getString("winRewards"));
                data.setBloodLossRewards(rs.getString("bloodLossRewards"));
                data.setDes(rs.getString("des"));
                data.setQuality(rs.getInt("quality"));
                data.setFailRewards(rs.getString("failRewards"));

                result.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
            //throw e;
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }

    public static String get5Sql = "select * from t_s_activity_five_hero_book where activityId= ?";
    public Map<Integer, FiveHeroBookConfig> getBookConfigMap(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, FiveHeroBookConfig> result = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(get5Sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FiveHeroBookConfig data = new FiveHeroBookConfig();
                data.setActivityId(rs.getInt("activityId"));
                data.setId(rs.getInt("id"));
                data.setName(rs.getString("name"));
                data.setDesc(rs.getString("desc"));
                data.setQuality(rs.getInt("quality"));
                data.setSchedule(rs.getInt("schedule"));
                data.setWeights(rs.getInt("weights"));
                data.setShowWeights(rs.getInt("showWeights"));
                data.setReward(rs.getString("reward"));
                data.setScheduleEffect(rs.getString("scheduleEffect"));
                data.setShowPos(rs.getString("showPos"));
                data.setShowScale(rs.getInt("showScale"));

                result.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
            //throw e;
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }

    public static String get6Sql = "select * from t_s_activity_five_hero_bandi where activityId= ?";
    public Map<Integer, FiveHeroBanditConfig> getBanditConfigMap(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, FiveHeroBanditConfig> result = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(get6Sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FiveHeroBanditConfig data = new FiveHeroBanditConfig();
                data.setActivityId(rs.getInt("activityId"));
                data.setId(rs.getInt("id"));
                data.setName(rs.getString("name"));
                data.setIcon(rs.getInt("icon"));

                result.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
            //throw e;
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }

    public static String get7Sql = "select * from t_s_activity_five_hero_tech where activityId= ?";
    public Map<Integer, FiveHeroTechConfig> getTechConfigMap(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, FiveHeroTechConfig> result = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(get7Sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FiveHeroTechConfig data = new FiveHeroTechConfig();
                data.setActivityId(rs.getInt("activityId"));
                data.setLevel(rs.getInt("level"));
                data.setAdd(rs.getInt("add"));
                data.setPerthAdd(rs.getInt("perthAdd"));
                data.setCost(rs.getInt("cost"));

                result.put(data.getLevel(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
            //throw e;
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }

    public static String get8Sql = "select * from t_s_activity_five_hero_order where activityId= ?";
    public Map<Integer, FiveHeroOrderConfig> getOrderConfigMap(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, FiveHeroOrderConfig> result = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(get8Sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FiveHeroOrderConfig data = new FiveHeroOrderConfig();
                data.setActivityId(rs.getInt("activityId"));
                data.setId(rs.getInt("id"));
                data.setName(rs.getString("name"));
                data.setRecoverNum(rs.getInt("recoverNum"));
                data.setTeamName(rs.getString("teamName"));

                result.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
            //throw e;
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }

    public static String get9Sql = "select * from t_s_activity_five_hero_title where activityId= ?";
    public Map<Integer, FiveHeroTitleConfig> getTitleConfigMap(int activityId) {
        ResultSet rs = null;
        CallableStatement call = null;
        Map<Integer, FiveHeroTitleConfig> result = new ConcurrentHashMap<>();
        try {
            getDb().setConnName(DbNameStrategy.getServerDb());
            call = getDb().getConnection().prepareCall(get9Sql);
            call.setInt(1, activityId);
            rs = call.executeQuery();
            while (rs.next()) {
                FiveHeroTitleConfig data = new FiveHeroTitleConfig();
                data.setActivityId(rs.getInt("activityId"));
                data.setId(rs.getInt("id"));
                data.setCampId(rs.getInt("campId"));
                data.setIcon(rs.getInt("icon"));
                data.setName(rs.getString("name"));
                data.setRewards(rs.getString("rewards"));

                result.put(data.getId(), data);
            }
        } catch (Exception e) {
            logger.error(Thread.currentThread().getStackTrace()[1].getMethodName() + ":", e);
            //throw e;
        } finally {
            getDb().closeConnection(call, rs);
        }
        return result;
    }
}
